﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Common
{
   public class GetCodeFromTypes
    {
       static XmlDocument doc = new XmlDocument();
       
       static GetCodeFromTypes()
       {
           doc.Load(PubConstant.ConfigPath + PubConstant.FullTypeToCodeName);
       }

       public static string GetCode(string FullTypeValue)
       {
          XmlNodeList xnl= doc.SelectNodes("//Root//Code");

          switch (FullTypeValue)
          {
              case "System.Boolean":
                  return FullTypeValue.ToLower();
              default:
                  return xnl.FindValue(new KeyValuePair<string, string>("FullType", FullTypeValue), "InnerText");
          }

       }

        //各个值的类型不同，生成的代码也不相同
        //switch (xnControlPro.Attributes["fullType"].Value)
        //{
        //    case "System.Boolean":
        //        sb2 = sb2.Replace("#$PropertyValue$#", xnControlPro.Attributes["value"].Value.ToLower());
        //        break;
        //    case "System.Drawing.Size":
        //        sb2 = sb2.Replace("#$PropertyValue$#", String.Format("new System.Drawing.Size({0})", xnControlPro.Attributes["value"].Value));
        //        break;
        //    case "System.Drawing.Point":
        //        sb2 = sb2.Replace("#$PropertyValue$#", String.Format("new System.Drawing.Point({0})", xnControlPro.Attributes["value"].Value));
        //        break;
        //    case "Event":
        //        sb2 = sb2.Replace("#$PropertyValue$#", String.Format("new System.EventHandler({0})", xnControlPro.Attributes["value"].Value));
        //        break;
        //    case "System.String":
        //        sb2 = sb2.Replace("#$PropertyValue$#", String.Format("\"{0}\"", xnControlPro.Attributes["value"].Value));
        //        break;
        //    case "Direct":
        //        sb2 = sb2.Replace("#$PropertyValue$#", String.Format("this.{0}", xnControlPro.Attributes["value"].Value));
        //        break;
        //    case "System.Windows.Forms.Dock":
        //        sb2 = sb2.Replace("#$PropertyValue$#", String.Format("System.Windows.Forms.DockStyle.{0}", xnControlPro.Attributes["value"].Value));
        //        break;
        //    case "DevExpress.XtraLayout.TextAlignModeItem":
        //        sb2 = sb2.Replace("#$PropertyValue$#", String.Format("DevExpress.XtraLayout.TextAlignModeItem.{0}", xnControlPro.Attributes["value"].Value));
        //        break;
        //    default: sb2 = sb2.Replace("#$PropertyValue$#", xnControlPro.Attributes["value"].Value);
        //        break;
        //}
    }
}
